package main

import (
    "net/http"
    "time"
)

func main() {
    p("ChitChat", version(), "started at", config.Address)

    // handle static files
    mux := http.NewServeMux()
    files := http.FileServer(http.Dir(config.Static))
    mux.Handle("/static/", http.StripPrefix("/static/", files))

    // err页面
    mux.HandleFunc("/err", err)

    // defined in route_auth.go
    mux.HandleFunc("/login", login)                  // 登录
    mux.HandleFunc("/authenticate", authenticate)    // 认证
    mux.HandleFunc("/signup", signup)                // 注册页面
    mux.HandleFunc("/signup_account", signupAccount) // 注册页面 post
    mux.HandleFunc("/logout", logout)                // 退出登录

    //  route_thread.go
    mux.HandleFunc("/thread/new", newThread) // 显示添加页面
    mux.HandleFunc("/thread/create", createThread) //   处理post 显示添加页面
    mux.HandleFunc("/thread/post", postThread)
    mux.HandleFunc("/thread/read", readThread)


    // 启动http服务器
    server := &http.Server{
        Addr:           config.Address,
        Handler:        mux,
        ReadTimeout:    time.Duration(config.ReadTimeout * int64(time.Second)),
        WriteTimeout:   time.Duration(config.WriteTimeout * int64(time.Second)),
        MaxHeaderBytes: 1 << 20,
    }
    server.ListenAndServe()
}
